# -*- coding:utf-8 -*-
# @FileName  :dhcc_per_own_report.py
# @Time      :2020/12/17 10:44
# @Author    :Zhoujirong
# @Desc      : 本人查询记录

import time
from biz.cases.base_case import BaseCase
from common.log import Log
from biz.flow.per_own_report import PerOwnReportRequest
from biz.flow.per_report import PerReportRequest
from biz.flow.per_reqresult import PerReqResultRequest
from common.utils import download

class TestPerOwnReport(BaseCase):
    data_file_name = 'per_own_report.yaml'
    @classmethod
    def setUpClass(cls) -> None:
        cls.cookie = BaseCase().get_token()

    def get_page(self):
        '''检索'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_customerName = self.file_data.get('search_EQ_customerName')
        search_EQ_certType = self.file_data.get('search_EQ_certType')
        search_EQ_certNo = self.file_data.get('search_EQ_certNo')
        search_EQ_qryReason = self.file_data.get('search_EQ_qryReason')
        search_EQ_queryType = self.file_data.get('search_EQ_queryType')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_queryFormat = '00'
        temp = '%s - %s'%(time.strftime('%Y-%m-%d',time.localtime()),time.strftime('%Y-%m-%d',time.localtime()))
        search_GTE_LTE_queryTime_DATE_RANGE = temp
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        ret = PerOwnReportRequest.get_page(curPage,
            maxSize,
            search_EQ_customerName,
            search_EQ_certType,
            search_EQ_certNo,
            search_EQ_qryReason,
            search_EQ_queryType,
            search_EQ_source,
            search_EQ_status,
            search_EQ_queryFormat,
            search_GTE_LTE_queryTime_DATE_RANGE,
            search_EQ_batchFlag,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return ret.list[0].id

    def detail(self):
        '''详情跳转'''
        id = self.get_page()
        ret = PerOwnReportRequest.detail(id,self.cookie)
        Log.info(ret)
        self.assertIn('本人查询记录详情',ret)
        return id

    def test_findbyid(self):
        '''详情'''
        id = self.detail()
        ret = PerOwnReportRequest.findbyid(id,self.cookie)
        Log.info(ret)
        self.assertEqual(id,ret.id)

    def test_exportload(self):
        '''导出一条'''
        search_EQ_customerName = self.file_data.get('search_EQ_customerName')
        search_EQ_certType = self.file_data.get('search_EQ_certType')
        search_EQ_certNo = self.file_data.get('search_EQ_certNo')
        search_EQ_qryReason = self.file_data.get('search_EQ_qryReason')
        search_EQ_queryType = self.file_data.get('search_EQ_queryType')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_queryFormat = '00'
        temp = '%s - %s' % (time.strftime('%Y-%m-%d', time.localtime()), time.strftime('%Y-%m-%d', time.localtime()))
        search_GTE_LTE_queryTime_DATE_RANGE = temp
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        ids = self.get_page()
        ret = PerOwnReportRequest.exportload(
            search_EQ_customerName,
            search_EQ_certType,
            search_EQ_certNo,
            search_EQ_qryReason,
            search_EQ_queryType,
            search_EQ_source,
            search_EQ_status,
            search_EQ_queryFormat,
            search_GTE_LTE_queryTime_DATE_RANGE,
            search_EQ_batchFlag,ids,self.cookie)
        Log.info(ret)
        size = download('单条个人本人查询记录dhcc_per_own_reportDtest_exportload%s.xls'%(time.strftime('%Y%m%d%H%M%S',time.localtime())),ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def test_exportload_all(self):
        '''导出全部'''
        search_EQ_customerName = ''
        search_EQ_certType = ''
        search_EQ_certNo = ''
        search_EQ_qryReason = ''
        search_EQ_queryType = ''
        search_EQ_source = ''
        search_EQ_status = ''
        search_EQ_queryFormat = ''
        search_GTE_LTE_queryTime_DATE_RANGE = ''
        search_EQ_batchFlag = ''
        ids = ''
        ret = PerOwnReportRequest.exportload(
            search_EQ_customerName,
            search_EQ_certType,
            search_EQ_certNo,
            search_EQ_qryReason,
            search_EQ_queryType,
            search_EQ_source,
            search_EQ_status,
            search_EQ_queryFormat,
            search_GTE_LTE_queryTime_DATE_RANGE,
            search_EQ_batchFlag,ids,self.cookie)
        Log.info(ret)
        size = download('all个人本人查询记录dhcc_per_own_reportDtest_exportload_all%s.xls'%(time.strftime('%Y%m%d%H%M%S',time.localtime())),ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def get_page_more(self):
        '''返回多条'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_customerName = ''
        search_EQ_certType = ''
        search_EQ_certNo = ''
        search_EQ_qryReason = ''
        search_EQ_queryType = ''
        search_EQ_source = ''
        search_EQ_status = ''
        search_EQ_queryFormat = ''
        search_GTE_LTE_queryTime_DATE_RANGE = ''
        search_EQ_batchFlag = ''
        ret = PerOwnReportRequest.get_page(curPage,
                                           maxSize,
                                           search_EQ_customerName,
                                           search_EQ_certType,
                                           search_EQ_certNo,
                                           search_EQ_qryReason,
                                           search_EQ_queryType,
                                           search_EQ_source,
                                           search_EQ_status,
                                           search_EQ_queryFormat,
                                           search_GTE_LTE_queryTime_DATE_RANGE,
                                           search_EQ_batchFlag, self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return ret.list


    def more_data(self):
        id_list = []
        list_data =  self.get_page_more()
        for data in list_data:
            id_list.append(data.id)
        ids = id_list[:2]
        ids = ','.join(ids)
        return ids

    def test_exportload_more(self):
        '''导出2条'''
        search_EQ_customerName = ''
        search_EQ_certType = ''
        search_EQ_certNo = ''
        search_EQ_qryReason = ''
        search_EQ_queryType = ''
        search_EQ_source = ''
        search_EQ_status = ''
        search_EQ_queryFormat = ''
        search_GTE_LTE_queryTime_DATE_RANGE = ''
        search_EQ_batchFlag = ''
        ids = self.more_data()
        ret = PerOwnReportRequest.exportload(
            search_EQ_customerName,
            search_EQ_certType,
            search_EQ_certNo,
            search_EQ_qryReason,
            search_EQ_queryType,
            search_EQ_source,
            search_EQ_status,
            search_EQ_queryFormat,
            search_GTE_LTE_queryTime_DATE_RANGE,
            search_EQ_batchFlag,ids,self.cookie)
        Log.info(ret)
        file_name = '2条个人本人查询记录dhcc_per_own_reportDtest_exportload_more%s.xls'%(time.strftime('%Y%m%d%H%M%S',time.localtime()))
        size = download(file_name,ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)


    def test_a_getstatus(self):
        '''本人是够可查看报告'''
        id = self.get_page()
        ret = PerOwnReportRequest.getstatus(id,self.cookie)
        Log.info(ret)
        self.assertIn('操作成功',ret.msg)
        self.assertEqual('00000000',ret.code)

    def revealreport(self):
        '''跳转报告'''
        id = self.get_page()
        ret = PerReqResultRequest.revealreport(id,self.cookie)
        Log.info(ret)
        self.assertIn('个人信用报告（银行版）',ret)
        return id

    def test_b_showcredit(self):
        '''展示信用报告'''
        id = self.revealreport()
        creditId = ''
        ret = PerReportRequest.per_show_credit(id,creditId,self.cookie)
        Log.info(ret)
        report_name = '个人信用报告dhcc_per_own_reportDtest_b_showcredit%s.html'%(time.strftime('%Y%m%d%H%M%S',time.localtime()))
        size = download(report_name,ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)







if __name__ == "__main__":
    pass